package com.hdaccp.dao.impl;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.hdaccp.dao.CommonDao;
import com.hdaccp.dao.ImgesDao;
import com.hdaccp.entity.Imges;
import com.hdaccp.util.BaseDao;

public class ImgesDaoimpl extends BaseDao implements CommonDao,ImgesDao {
    @Override
    public List getAll() {
    	
        return null;
    }

    @Override
    public Object getById(Serializable id) {
        return null;
    }

    @Override
    public boolean add(Object entity) {
        return false;
    }

    @Override
    public boolean update(Object entity) {
        return false;
    }

    @Override
    public boolean deleteById(Serializable id) {
        return false;
    }

	@Override
	public int count(int id) {
		String sql = "select count(*) from imges where zid = ?";
		Object[] object = {id};
		ResultSet set = super.executeQuery(sql, object);
		int fan = 0;
		try {
			while(set.next()){
				fan = set.getInt(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				super.closeAll(set, set.getStatement(), set.getStatement().getConnection());
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return fan;
	}

	@Override
	public List<Imges> query(int id) {
		String sql = "select * from imges where zid = ?";
		Object[] object = {id};
		ResultSet set = super.executeQuery(sql, object);
		List<Imges> list = new ArrayList<Imges>();
		try {
			while(set.next()){
				Imges imges = new Imges();
				imges.setId(set.getInt(1));
				imges.setImg(set.getString(2));
				imges.setZid(set.getInt(3));
				list.add(imges);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				super.closeAll(set, set.getStatement(), set.getStatement().getConnection());
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return list;
	}

	@Override
	public boolean add(Imges s) {
		String sql = "insert into `construction`.`imges` (`img`, `zid`) values (?, ?); ";
		Object[] object = {s.getImg(),s.getZid()};
		
		return super.executeUpdate(sql, object);
	}

	@Override
	public boolean del(int id) {
		String sql = "delete from imges where id = ?";
		Object[] object = {id};
		return super.executeUpdate(sql, object);
	}
}
